package com.infore.siteManagement.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.siteManagement.constant.Constants;
import com.infore.siteManagement.dto.AreaDto;
import com.infore.siteManagement.entity.Area;
import com.infore.siteManagement.enums.ResultStatus;
import com.infore.siteManagement.select.dto.QueryParamDto;
import com.infore.siteManagement.service.IAreaService;
import com.infore.siteManagement.util.ResultEntity;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "区域管理接口", tags = {"区域管理接口" })
@RestController
@RequestMapping("/area")
public class AreaController {

	@Autowired
	private IAreaService iAreaService;
	
	@ApiOperation(value = "查询区域通用接口")
	@ResponseBody
	@PostMapping(value = "/query")
	public ResultEntity queryArea(@RequestBody(required = false) QueryParamDto queryParamDto) {
		return iAreaService.queryArea(queryParamDto);
	}
	
	@ApiOperation(value = "删除区域通用接口")
	@ApiImplicitParams(@ApiImplicitParam(value = "区域id", name = "ids", paramType = "query",required = true,dataType = "String"))
	@DeleteMapping(value = "/delete")
	public ResultEntity deleteArea(String ids) {
		return iAreaService.deleteArea(ids);
	}
	
	@ApiOperation(value = "编辑/新增区域通用接口")
	@ResponseBody
	@PostMapping(value = "/edit")
	public ResultEntity editArea(@RequestBody Area area) {
		return iAreaService.editArea(area);
	}
	
	@ApiOperation(value = "验证区域通用接口")
	@ResponseBody
	@PostMapping(value = "/validate")
	public ResultEntity validateArea(@RequestBody Area area) {
		return iAreaService.validateArea(area);
	}
	
	@ApiOperation(value = "得到省份下所有城市信息")
	@ApiImplicitParams(@ApiImplicitParam(value = "区县", name = "name", paramType = "query",required = true,dataType = "String"))
	@GetMapping(value = "/areaInfo")
	public ResultEntity areaInfo(String name) {
		return iAreaService.areaInfo(name);
	}
	
	@ApiOperation(value = "得到所有省份信息")
	@ResponseBody
	@GetMapping(value = "/provinceInfo")
	public ResultEntity provinceInfo() {
		return iAreaService.provinceInfo();
	}
	
	@ApiOperation(value = "国----编辑/新增区域接口")
	@ResponseBody
//	@ApiImplicitParams({@ApiImplicitParam(value = "区域编码", name = "code", paramType = "query",required = true,dataType = "String"),
//		@ApiImplicitParam(value = "区域名称", name = "name", paramType = "query",required = true,dataType = "String"),
//	@ApiImplicitParam(value = "上级区域编码", name = "fatherCode", paramType = "query",required = true,dataType = "String"),
//	@ApiImplicitParam(value = "区域等级id", name = "levelId", paramType = "query",required = true,dataType = "String"),
//	@ApiImplicitParam(value = "备注", name = "remark", paramType = "query",required = false,dataType = "String"),
//	@ApiImplicitParam(value = "区域id", name = "areaId", paramType = "query",required = false,dataType = "String"),
//	@ApiImplicitParam(value = "区域水质目标等级", name = "aimWaterLevel", paramType = "query",required = false,dataType = "String"),
//	@ApiImplicitParam(value = "排序", name = "sort", paramType = "query",required = false,dataType = "String")})
	@PostMapping(value = "/addOrEdit")
	public ResultEntity addOrEdit(@RequestBody AreaDto areaDto) {
		return iAreaService.addOrEdit(areaDto);
	}
	
	@ApiOperation(value = "区域树结构接口")
	@ResponseBody
	@GetMapping(value = "/areaTree")
	public ResultEntity areaTree(String name) {
		return iAreaService.areaTree(name);
	}
	
	@ApiOperation(value = "区域所有父级点")
    @ResponseBody
    @GetMapping(value = "/areaParents")
    public ResultEntity areaParents(String codes) {
        return new ResultEntity(ResultStatus.SUCCESS,Constants.QUERY_SUCCESS)
                .setDataList(iAreaService.areaParents(codes));
    }
}
